import { IQuestionBuilder } from './IQuestionBuilder'
import { IQuestion } from '../../Model/Question'

/**
 * 猜数字题目构造辅助
 *
 * @example
 * const question = GuessNumQuestionBuilder.Build()
 */
export class GuessNumQuestionBuilder extends IQuestionBuilder {
  /**
   * 构造猜数字题目
   */
  public static Build (): IQuestion {
    let tmpQuestion = ''
    for (let i = 0; i < 4; i++) {
      let tmpNum: number
      do {
        tmpNum = Math.floor(Math.random() * 9) // 随机产生 0~10之间的数字 向下取整。 包含 0 不包含 10
      } while (tmpQuestion.indexOf(tmpNum.toString()) !== -1)

      tmpQuestion += tmpNum.toString()
    }

    return ({
      Question: tmpQuestion
    })
  }
}
